import xlwt#写excel用
import Read_data
import PCAprocess

'''
写文件模块
输入：起文件名（.xls结尾），数据（list）
输入：xls文件
'''



class write_data:
    def __init__(self,filename,data):
        self.filename=filename
        self.data =data
        self.mainProcess()

    def mainProcess(self):
        self.write_ronghe()
        print("成功写入"+self.filename)


    #输出数据为文件
    def write_ronghe(self):
        #打开文件
        workbook = xlwt.Workbook(encoding='utf-8')
        booksheet = workbook.add_sheet('Sheet 1', cell_overwrite_ok=True)
        row=-1#从第0行开始写
        col=-1#从第0列开始写
        for list1 in self.data:  
            row += 1
            col = -1
            for list2 in list1:
                col +=1
                booksheet.write(row, col, list2)
        #workbook.save('./jiuzhaigou_PCA_jiangwei_Data_real.xls')
        workbook.save(self.filename)

# #联调测试
# rd=Read_data.Read_data("data_siguniangshan.xlsx",1,13)
# sdata=rd.outputdata
# pcaP=PCAprocess.PCAprocess(sdata,3)
# pcaD=pcaP.output_data
# Write_data("write_test.xls",pcaD)